package com.nulldev.util.java.date;

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

import com.nulldev.util.math.MathUtil;
import com.nulldev.util.math.lNumber;

public class DateUtil {

	public static Date create(final int year, final int month, final int date) {
		final Calendar calendar = Calendar.getInstance();
		calendar.clear();
		calendar.set(Calendar.MONTH, month);
		calendar.set(Calendar.YEAR, year);
		calendar.set(Calendar.DATE, date);
		return calendar.getTime();
	}
	
	public static Date create(final lNumber time) {
		final Calendar calendar = Calendar.getInstance();
		calendar.clear();
		calendar.setTimeInMillis(time.longValue());
		return calendar.getTime();
	}
	
	public static Date create(final long time) {
		final Calendar calendar = Calendar.getInstance();
		calendar.clear();
		calendar.setTimeInMillis(time);
		return calendar.getTime();
	}
	
	public static Date get() {
		final Calendar calendar = Calendar.getInstance();
		return calendar.getTime();
	}
	
	public static Date getUTC() {
		final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
		return calendar.getTime();	
	}
	
	public static lNumber UTC() {
		final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
		return lNumber.fromLong(calendar.getTime().getTime());	
	}

	public static String hms() {
		final Date d = get();
		return MathUtil.timeZero(d.getHours()) + ":" + MathUtil.timeZero(d.getMinutes());
	}
	
	public static Date createFromMills(final long time) {
		final Calendar calendar = Calendar.getInstance();
		calendar.clear();
		calendar.setTimeInMillis(time);
		return calendar.getTime();
	}
}
